package com.cade.agriculturemall.view.home.search;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.cade.agriculturemall.R;
import com.cade.agriculturemall.model.GoodsDetailEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hshunxin on 2018/2/23.
 */

public class SeekAdapter extends RecyclerView.Adapter<SeekAdapter.ViewHolder> {
    private Context mContext;
    private List<GoodsDetailEntity> entities = new ArrayList<>();
    private LayoutInflater mInflater;


    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (entities != null) {
            GoodsDetailEntity entity = entities.get(position);
            holder.titleTv.setText(entity.getTitle() + position);
            holder.priceTv.setText("￥ " + entity.getPriceNew());
            if (entity.getPicture() == null) {
                Glide.with(mContext).load(entity.getPicture().get(0)).into(holder.imageView);
            }
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new SeekAdapter.ViewHolder(mInflater.inflate(R.layout.item_collect, null));
    }


    @Override
    public int getItemCount() {
        return entities.size();
    }

    public SeekAdapter(Context context, List<GoodsDetailEntity> list) {
        mContext = context;
        entities = list;
        mInflater = LayoutInflater.from(context);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView titleTv;
        TextView priceTv;
        ImageView imageView;

        public ViewHolder(View itemView) {
            super(itemView);
            titleTv = (TextView) itemView.findViewById(R.id.item_collect_title);
            priceTv = (TextView) itemView.findViewById(R.id.item_collect_price);
            imageView = (ImageView) itemView.findViewById(R.id.item_collect_imageView);
        }
    }
}
